$(document).ready( function(){
	$(".contactForm").on("click", "button", function(){
		$("#ajaxLoader").show();
		var dataString = $(".contactForm").serialize();
		dataString += "&contact=1";
		
		$.ajax({
				type:'POST',
				url: scriptsURL+"libs/ajax/ajax-includes.php",
				data: dataString,
				success: function(responseJSON)
				{
					var response = JSON.parse(responseJSON);
					var message = "";
					if(response.error_count && response.error_count > 0)
					{
						
						$.each( response, function( key, value ) {
							if($(".contactForm input[name="+key+"]").length > 0 || $(".contactForm textarea[name="+key+"]").length > 0)
							{
								$(".contactForm input[name="+key+"], .contactForm textarea[name="+key+"]").parent().addClass("has-error");
								message += '<div class="alert alert-danger">'+value+'</div>';
							}
						});
					}
					else
					{
						message = '<div class="alert alert-success">'+response.message+'</div>';
					}
					
					$("#messageDialog .modal-body").html(message);
					$('#messageDialog').modal('show');
					
					$("#newCaptcha").trigger("click");
					$("#ajaxLoader").hide();
				}
		});
		return false;
	});
	$("body").on("change",".has-error input, .has-error textarea", function(){
		if($(this).val() != "")
		{
			$(this).parent().removeClass("has-error");
		}
	});
});
